<?php
/*
Template Name: 福建寺院
 */
    get_header();
?>
<!-- 列表模块 -->
<div class="main-container">
    <div class="wrap">
        <p class="page-title">福建寺院</p>
        <div class="common-tab-switch">
            <a href="/fj-temple/fuzhou-temple" title="">福州</a>
            <a href="/fj-temple/xiamen-temple" title="">厦门</a>
            <a href="/fj-temple/zhangzhou-temple" title="">漳州</a>
            <a href="/fj-temple/quanzhou-temple" title="">泉州</a>
            <a href="/fj-temple/sanming-temple" title="">三明</a>
            <a href="/fj-temple/putian-temple" title="">莆田</a>
            <a href="/fj-temple/longyan-temple" title="">龙岩</a>
            <a href="/fj-temple/nanping-temple" title="">南平</a>
            <a href="/fj-temple/ningde-temple" title="">宁德</a>
            <a href="/fj-temple/pingtan-temple" title="">平潭综合实验区</a>
        </div>
        <ul class="temple-container">
            <?php
                $thisTem = array_slice(explode('/', get_the_permalink($post)), -1)[0];
                $temArray = array('fuzhou-temple', 'xiamen-temple', 'zhangzhou-temple', 'quanzhou-temple', 'sanming-temple', 'putian-temple', 'longyan-temple', 'nanping-temple', 'ningde-temple', 'pingtan-temple');
                $tempCat = array_search($thisTem, $temArray) + 14;
                query_posts(array(
                    'showposts'=>10,
                    'offset'=>max( 1, get_query_var('paged') )-1,
                    'cat'=>$tempCat
                ));
                while(have_posts()) {
                    the_post();
            ?>
            <li class="clearfix">
                <a class="temple-preview" href="<?php the_permalink(); ?>" title="">
                    <?php the_post_thumbnail(array(170, 100)); ?>
                </a>
                <div class="temple-right">
                        <h3><a href="<?php the_permalink(); ?>" title=""><?php the_title(); ?></a></h3>
                        <p><?php the_excerpt(); ?></p>
                </div>
            </li>
            <?php
                }
                wp_reset_query();
            ?>
        </ul>
        <div class="pagination" id="pagination">
        <?php 
            $allsearch = new WP_Query(array(
                'cat'=>6
            ));
            par_pagenavi($allsearch, 25); 
        ?>
        </div>
    </div>
</div>
<?php
    get_footer();
?>
<script>
(function() {
    var pageTotal = parseInt($('.pagination-total em').text());
    $('.pagination-go').on('click', function() {
        var val = parseInt($(this).siblings('input').val());
        if (isNaN(val) || val < 1 || val > pageTotal) {
            alert('请输入1~' + pageTotal + '之间的页码数');
            return;
        }
        var href = 'http://' + location.host + '/news/page/' + val;
        location.href = href;
    }); 
})();
</script>
<script>
    (function() {
        var
        fileName=location.pathname.split('/').pop(),
        $nav=$('.common-tab-switch');
        $nav.find('a').each(function() {
            console.log($(this).attr('href').split('/')[2])
            if ($(this).attr('href').split('/')[2] === fileName) {
                $(this).addClass('on');
                return false;
            }
        });
    })();
</script>
</body>
</html>